package com.ruoyi.common.core.annotation.valid.impl;


import com.ruoyi.common.core.annotation.MobileValid;
import com.ruoyi.common.core.utils.MobileUtils;
import lombok.Data;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

@Data
public class MobileValidValidator implements ConstraintValidator<MobileValid, Object> {
    private MobileValid mobileValid;

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        return MobileUtils.validMobile(String.valueOf(value));
    }

    @Override
    public void initialize(MobileValid constraintAnnotation) {
        mobileValid = constraintAnnotation;
    }
}
